#include "stdio.h"
#include "unistd.h"
#include "sys/types.h"
#include "sys/stat.h"
#include "fcntl.h"
#include "stdlib.h"
#include "string.h"

#define LEDOFF 	0
#define LEDON 	1

//times delay
int main(int argc, char *argv[])
{
    int led,blink_times,delay;
    int retvalue;
    char *filename="/dev/led";

    delay=atoi(argv[1]);
    if(argc > 3){
        printf("error\r\n");
        return -1;
    }

    led=open(filename,O_RDWR);
    if(led<0){
        printf("file %s open failed!\r\n",filename);
        return -1;
    }

    blink_times=atoi(argv[2]);
    printf("%d\r\n",blink_times);

    for(int i=0;i<blink_times;i++){
        retvalue=write(led,0,sizeof(1));
        usleep(delay*100);
        retvalue=write(led,1,sizeof(0));
        usleep(delay*100);
    }

    retvalue=close(led);
    if (retvalue<0){
        printf("file %s close failed!\r\n",filename);
        return -1;
    }
    
    return 0;

}